package ch.ethz.fcl.process.polygon;

import java.util.ArrayList;
import java.util.List;

import org.opencv.core.Point;

/**
 * A group of lines with angle information
 * 
 * @author crazyfrog
 * 
 */
public class LineGroup {
	List<Line> lines;
	float length;

	public LineGroup() {
		lines = new ArrayList<Line>();
	}

	public void addLine(Line line) {
		lines.add(line);
		length += line.length();
	}

	public Point centroid() {
		double x = 0, y = 0;
		for (Line l : lines) {
			x += l.p1.x;
			x += l.p2.x;
			y += l.p1.y;
			y += l.p2.y;
		}
		return new Point(x / (lines.size() * 2), y / (lines.size() * 2));
	}

	public Line toLine(double angle) {
		Line line = new Line(centroid(), angle, length);
		return line;
	}
}
